      $('.select2').select2();

	   $('#datepicker').datetimepicker({
	   	format:'YYYY-MM-DD HH:mm:ss'
        })
	   
	   
	   
	  function pic_replace(dom1,dom2){
	  	var file = document.getElementById(dom1).files;
	  	var reader = new FileReader();
	  	reader.readAsDataURL(file[0]);
	  	reader.onload = function(e){
	  	  var Img = '<img class="img_sty" src="'+this.result+'" width="85px" height="100px"/>';
	  	  $('.'+dom2).html(Img)
	  	}
	  }
	  //规格添加
			/*	  Fn();
				  
				 function Fn(){
				 $('.kind_increase_btn').click(function(){
					 	$('.kind_box').css('display','block');
					 	$('.increase_inp').before('<input class="form-control" type="text" />')
					 	$('.kind_box_3').append('<input class="form-control" type="text" />')
					 	
					 	$('.increase_inp').click(function(){
					 		$('.increase_inp').before('<input class="form-control" type="text" />')
					 		$('.kind_box_3').append('<input class="form-control" type="text" />')
					 	})
					 	$('.reduce_inp').click(function(){
					 		if($('.kind_box_3 input').length==1){
					 			$('.kind_box').css('display','none');
					 		}
					 		$('.kind_box_2 input').last().remove();
					 		$('.kind_box_3 input').last().remove();
					 	})
					 	})
					 }*/
	 $('.submit_all').click(function(){
	   	 //上架时间
	   	   var timeKind= $('input:radio[name="OnlineModel"]:checked').val();
	   	 
	   	  var Text = $('.kind_box_3').find('input');
	    	var Kind_text = $('.kind_box_2').find('input');
	    	var textOnoff = true;
	    	
	    	//var filesInput = $('input[type=file]');
	    	  
	    		
	    	
	    	
	   	 //判断必填信息
	    	 if($('input[name=Name]').val()==''&&textOnoff==true){
		   	 	textOnoff = false;
		   	 	layer.msg('请填写商品名称')
		   	 	
		   	 }else if($('input[name=Describes]').val()==''&&textOnoff==true){
		   	 	textOnoff = false;
		   	 	layer.msg('请填写商品描述')
		   	 	
		   	 }else if($('input[name=Price]').val()==''&&textOnoff==true){
		   	 	textOnoff = false;
		   	 	layer.msg('请填写商品价格')
		   	 	
		   	 }else if($('.occcation').select2('val')==''&&textOnoff==true){
		   	 	textOnoff = false;
		   	 	layer.msg('请选择商品分组')
		   	 	
		   	 } else if(Kind_text.length==0&&textOnoff==true){
		   	 	layer.msg('请添加规格');
		   	 	textOnoff =false;
		   	 }else if($('#radio3').prop('checked')==true&&$('.data_pick').val()==''){
		   	 	layer.msg('请选择自定义上架时间');
		   	 	        textOnoff =false;
		   	 }else if($('.file_img1').text()=='+'&&textOnoff==true){
		   	 	layer.msg('请添加商品缩略图');
		   	 	textOnoff =false;
		   	 }else if($('.detail_pic').text()=='+'&&textOnoff==true){
		   	 	layer.msg('请添加商品详情介绍图');
		   	 	textOnoff =false;
		   	 }else{
		   	 	
		   	 	for (var i=0;i<$('.pic_l').length;i++) {
		   	 		if($('.pic_l').eq(i).text()=='+'){
		   	 			layer.msg('请添加商品轮播图至5张');
		   	 	        textOnoff =false;
		   	 		}
		   	 	}
		   	 	
		   	 }
		   
	    	for (var i=0;i<Text.length;i++) {
	    		var Num = Number(Text.eq(i).val());
	    		if(Math.round(Num) !== Num){
	    			layer.msg('请填写整数');
	    			textOnoff = false;
	    		}
	    	}
	   	 
	   	 
	   	
	   	 var dataSend=[];
	     var inp_num;
	     var all_num=0;
	
	   	 
	   	 for (var i=0;i<Kind_text.length;i++) {
	    			
		    		if(Text.eq(i).val()==''){
		    			inp_num=0;
		    			all_num+=Number(Text.eq(i).val())
		    		}else{
		    			inp_num=Number(Text.eq(i).val());
		    			all_num+=Number(Text.eq(i).val())
		    		}
		    		
		    		if(Kind_text.eq(i).val()==""){
		    			layer.msg('请完整填写整规格');
		    			textOnoff = false;
		    		}else{
		    			dataSend.push(Kind_text.eq(i).val()+'-'+inp_num);
		    		}
	    			
	    		}
	   	 
	   	 if(textOnoff){
	   	 	  var formData = new FormData(document.getElementById('new_form3'));
	    		var pic_num=0;//轮播图数量
	    		for (var i=0;i<$('.pic_l').length;i++) {
	    			if($('.pic_l').eq(i).find('img').length==1){
	    				pic_num+=1;
	    			}
	    		}
	    		
	    		//图片汉字修改
	    		/*
		    		for (var i = 0;i<filesInput.length;i++) {
		    			var file_el = filesInput.eq(i).prop('id');//jq选择器不支持file对象
		    			var file_con = document.getElementById(file_el).files;
		    			var file_name = filesInput.eq(i).attr('namel');//name值
		    			if(file_con[0]!=undefined){
				    			var random_str = '';//随机字符串
				    			var pic_kind = file_con[0]['name'];
			
				    			for (var j=0;j<5;j++) {
				    				random_str+=String.fromCharCode(Math.round(Math.random()*(25)+97));
				    			}
				    			 
				    			file_con[0]['name'] = random_str+pic_kind;
				    			formData.append(file_name,file_con);
		    			}else{
		    				formData.append(file_name,'');
		    			}
		    			
		    		}
			   	*/
			   	 formData.append('Color',$(".sel").eq(0).select2('val'));
			   	 formData.append('Fabric',$(".sel").eq(1).select2('val'));
			   	 formData.append('Thickness',$(".sel").eq(2).select2('val'));
			   	 formData.append('Model',$(".sel").eq(3).select2('val'));
			   	 formData.append('Neck',$(".sel").eq(4).select2('val'));
			   	 formData.append('Ymj',$(".sel").eq(5).select2('val'));
			   	 formData.append('Season',$(".sel").eq(6).select2('val'));
			   	 formData.append('Type',$(".occcation").select2('val').join('_'))
			   	 formData.append('Standard',dataSend.join('_'));
			   	 formData.append('Stock',all_num);
			   	 formData.append('ImageNumber',pic_num);
			   	 
			   	 $.ajax({
			   	 	type:"POST",
			   	 	url:"https://www.retux.cn/MgNewProduct/",
			   	 	async:true,
			   	 	data: formData,
						processData: false,
						contentType: false,
						success: function(data) {
							if(data=='success'){
								layer.msg('提交成功',{time:500},function(){
									window.location.href = 'http://119.23.212.200:30000/product_list.html';
								})
							   
							}else if(data=='error'){
								layer.msg('商品名称重复')
							    location.reload();
							}else{
								layer.msg('提交失败')
							}
						}
			   	 });
	   	  }
	   })
	